package com.aiyige.utils.widget;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by zhuyakun on 2017/12/15.
 */

public class NumberUtil {
    //金额验证
    public static boolean isNumberWithTwoDecimal(String str) {
        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"); // 判断小数点后2位的数字的正则表达式
        Matcher match = pattern.matcher(str);
        if (match.matches() == false) {
            return false;
        } else {
            return true;
        }
    }


    public static boolean safeEquals(Long a, Long b) {
        if (a == null && b == null) {
            return true;
        } else if (a == null || b == null) {
            return false;
        } else {
            return a.equals(b);
        }
    }


    public static boolean safeEquals(Integer a, Integer b) {
        if (a == null && b == null) {
            return true;
        } else if (a == null || b == null) {
            return false;
        } else {
            return a.equals(b);
        }
    }

    public static boolean safeEquals(Double a, Double b) {
        if (a == null && b == null) {
            return true;
        } else if (a == null || b == null) {
            return false;
        } else {
            return a.equals(b);
        }
    }

    public static boolean safeEquals(Float a, Float b) {
        if (a == null && b == null) {
            return true;
        } else if (a == null || b == null) {
            return false;
        } else {
            return a.equals(b);
        }
    }
}
